//4：假设有个Socket服务器，提供查询气温，风力，pm2.5,湿度等气象服务
import java.io.*;
import java.net.Socket;
import java.util.Scanner;

public class WeatherClient {
    public static void main(String[] args)  {
        Socket socket = null;
        InputStream in=null;
        OutputStream out=null;
        PrintWriter writer =null;
        BufferedReader reader  =null;
        try {
            socket = new Socket("127.0.0.1", 9999);
        in = socket.getInputStream();
        out = socket.getOutputStream();
        writer = new PrintWriter(out, true);
        Scanner put = new Scanner(System.in);
        while (true) {
            System.out.println("输入选择：气温，风力，PM2.5，湿度");
            String str = put.next();
            writer.println(str);

           reader  = new BufferedReader(new InputStreamReader(in));
            String line = "  ";
            while ((line = reader.readLine())!=null) {
                if (line.equals("0")){
                    break;
                }
                System.out.println(line);
                if (line.equals("exit")) {
                    return;
                }
            }
        }
   } catch (IOException e) {
        throw new RuntimeException(e);
    }
        finally {
            try {
                in.close();
                out.close();
                writer.close();
                reader.close();
                socket.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }

        }
    }
}